<?php
ob_start();
session_start();

	require ("main_function.php"); 
	require ("cek_session.php"); 
	
	if (empty($_POST['gen1'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 1 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen2'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 2 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen3'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 3 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen4'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 4 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen5'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 5 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen6'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 6 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen7'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 7 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen8'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 8 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen9'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 9 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}elseif (empty($_POST['gen10'])){
		echo '<script type="text/javascript">';
		echo 'alert(\'Soal no 10 belum dipilih '.'\');';
		echo 'location.href = \'soal1.php\';';
		echo '</script>';
	}else{
	$pgl = array ($_POST['gen1'],$_POST['gen2'],$_POST['gen3'],$_POST['gen4'],$_POST['gen5'],$_POST['gen6'],$_POST['gen7'],$_POST['gen8'],$_POST['gen9'],$_POST['gen10']);
	for ($l=0;$l<=10;$l++)
		{
		if ($pgl[$l] == "A")
			{
			$A = $A + 1 ;
			}
		elseif ($pgl[$l] == "B")
			{
			$B = $B + 1;
			}
		elseif ($pgl[$l] == "C")
			{
			$C = $C + 1;
			}
		elseif ($pgl[$l] == "D")
			{
			$D = $D + 1;
			}
		}
	$cekisi="SELECT * FROM tkarakter where kdKarak='".$_SESSION["uid"]."'";
	$runcek=mysql_query($cekisi) or die(mysql_error());
	$num_query = mysql_affected_rows();
	if ($num_query == 0) {
		$isn="INSERT INTO tkarakter VALUES ('".$_SESSION["uid"]."','".$A."','".$B."','".$C."','".$D."')";
		$runisn=mysql_query($isn) or die("error".mysql_error());
		$num_query2 = mysql_affected_rows();
		if ($num_query2 == 1) {
			$date=date("Y")."-".date("n")."-".date("d");
			$isn2="INSERT INTO ttran_karak VALUES ('".$_SESSION["uid"]."','".$_SESSION["nm"]."','".$date."','".$A."','".$B."','".$C."','".$D."')";
			$runisn2=mysql_query($isn2) or die(mysql_error());
			$num_query3 = mysql_affected_rows();
			if ($num_query3 == 1) {
				header('location: soal2.php');
			}
		}
	}
	}
	
mysql_close($konk);
?>
